<?php

session_start();
if(!isset($_SESSION['userId']))
{
	header("location:index.php");
}
include("../class/config.php");
include("../class/cls_contact.php");

if(isset($_POST['send']))
{
	$contact_name=$_POST['contact_name'];
	$contact_email=$_POST['contact_email'];
	$contact_subject=$_POST['contact_subject'];
	$contact_message=$_POST['contact_message'];
	$date=date("Y-m-d");
	$objContact->sendmail($to=_SEND_EMAIL_,$name=_SEND_NAME_,$sub=$contact_subject,$msg=$contact_message,$senderEmail=$contact_email,
	$senderName=$contact_name);
	$objContact->addContact($contact_name,$contact_email, $contact_subject,$contact_message,$date);
	$success="Contact added successfully.";
}
if(isset($_GET['deleteId']))
{
	$contactId=$_GET['deleteId'];
	$objContact->deleteContact($contactId);
	}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact</title>
<link rel="stylesheet" href="../css/layout.css" />
</head>
<body>

	<div class="mainWrapper">
     <?php include("../includes/adminHeader.php");?>
    
    
    <div class="bodyContent">
    <h1>Contact</h1>
    <div class="innerBody">
    <strong>Contact Listing</strong>  
     
	
      <table width="100%" border="0" cellpadding="1" cellspacing="1" class="table">
        <tr>
          <th>Sn</th>
          <th>Contact Added Date</th>
          <th>Contact Name</th>
          <th>Contact Email</th>
          <th>Contact Subject</th>
          <th>Contact Message</th>
          <th>Action</th>
        </tr>
		<?php $resContact = $objContact->selectContact();
		$i=1;
		
		while($recContact=mysqli_fetch_array($resContact))
		{
		?>
        <tr>
          <td><?php echo $i++;?></td>
          <td><?php echo $recContact['contact_added_date'];?></td>
          <td><?php echo $recContact['contact_name'];?></td>
          <td><?php echo $recContact['contact_email'];?></td>
          <td><?php echo $recContact['contact_subject'];?></td>
          <td><?php echo $recContact['contact_message'];?></td>
		  
          <td><a href="?deleteId=<?php echo $recContact['contact_id'];?>" onclick="javascript:return confirm('Are You Sure You Want to Delete this Record?')">Delete</a></td>
        </tr>
        <?php }?>
       </table>
       
    </div>
    
   </div>
    
    
    <?php //include("../includes/adminFooter.php");?>
     
 </div>

</body>
</html>